package com.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.*;
import javax.validation.constraints.Email;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 * User entity.
 */
@Data
@Entity
@Table(name = "sys_user")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserInfo implements Serializable {

    private static final long serialVersionUID = -4403726862341742090L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "用户表id")
    private Integer id;

    /**
     * Username.
     */
    @Column(name = "username")
    @ApiModelProperty(value = "用户名")
    private String username;

    @Column(name = "nickname")
    @ApiModelProperty(value = "用户昵称")
    private String nickname;
    /**
     * Password.
     */
    @Column(name = "password")
    @ApiModelProperty(value = "用户密码")
    private String password;


    @Column(name = "introduction")
    @ApiModelProperty(value = "用户自我描述")
    private String introduction;


    @Column(name = "avatar")
    @ApiModelProperty(value = "头像信息")
    private String avatar;

    @Column(name = "is_admin")
    @ApiModelProperty(value = "用户是否为管理员")
    private boolean  isAdmin;

    @Column(name = "is_enable")
    @ApiModelProperty(value = "用户是否被启用")
    private boolean enabled;

    @Column(name = "pwd_rest_time")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @ApiModelProperty(value = "重置密码时间")
    private Date changedPwd;


    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @ApiModelProperty(value = "创建时间")
    @Column(name = "create_time")
    private Date  createdTime;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间")
    private Date updatedTime;

    @Column(name = "status")
    @ApiModelProperty(value = "此用户状态信息")
    private Integer status;

    @Column(name = "phone")
    @ApiModelProperty(value = "用户手机号")
    private String phone;
    @Email
    @Column(name = "email")
    @ApiModelProperty(value = "用户邮箱号")
    private String email;
    //一对多关系映射
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name="sys_user_role",//中间表的名称
            //中间表user_role字段关联sysuser表的主键字段id
            joinColumns={@JoinColumn(name="uid",referencedColumnName="id")},
            //中间表user_role的字段关联sysrole表的主键id
            inverseJoinColumns={@JoinColumn(name="rid",referencedColumnName="id")}

    )
    private List<Role> roles;

}

